package com.liu.seckill.config;

import com.liu.seckill.service.IGoodsService;
import com.liu.seckill.vo.GoodsVo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @ClassName RedisConfig
 * @Author ：name
 * @Date ：2022-02-15 14:37
 * @Description： Redis配置类
 * @Version: 1.0
 */
@Configuration
public class RedisConfig{

    @Autowired
    private IGoodsService goodsService;
    @Autowired
    private  RedisTemplate redisTemplate;
      @Bean
  public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory
                                                             connectionFactory){
   RedisTemplate<String,Object> redisTemplate = new RedisTemplate<>();
   //key序列器
   redisTemplate.setKeySerializer(new StringRedisSerializer());
   //value序列器
   redisTemplate.setValueSerializer(new
                GenericJackson2JsonRedisSerializer());
   //Hash类型 key序列器
   redisTemplate.setHashKeySerializer(new StringRedisSerializer());
   //Hash类型 value序列器
   redisTemplate.setHashValueSerializer(new
                GenericJackson2JsonRedisSerializer());
   redisTemplate.setConnectionFactory(connectionFactory);
   return redisTemplate;
  }



}
